package com.ruide.dao;

import java.util.List;

import com.ruide.db.DBManager;
import com.ruide.mapper.bankUsersMapper;
import com.ruide.vo.bankUsers;

public class bankUsersDAO {
	public int save(bankUsers u){
		String sql="insert into bankUsers values(?,?,?,?)";
		Object params[]={u.getUserId(),u.getUsername(),u.getUserpass(),u.getMoney()};
		DBManager db=new DBManager();
		int i=db.executeUpdate(sql, params);
		return i;
	}
	public int delete(int id){
		String sql="delete from bankusers where userid=?";
		Object params[]={id};
		DBManager db=new DBManager();
		int i=db.executeUpdate(sql, params);
		return i;
	}
	public int merge(int money,int userid){
		String sql="update bankusers set money=? where userid=?";
		Object params[]={money,userid};
		DBManager db=new DBManager();
		int i=db.executeUpdate(sql, params);
		return i;
	}
	public int mergepass(String pass,int userid){
		String sql="update bankusers set userpass=? where userid=?";
		Object params[]={pass,userid};
		DBManager db=new DBManager();
		int i=db.executeUpdate(sql, params);
		return i;
	}
	public List<bankUsers> findAll(){
		String sql="select * from bankusers order by userid";
		Object params[]=null;
		DBManager db=new DBManager();
		bankUsersMapper mapper=new bankUsersMapper();
		List<bankUsers> list=db.executeQuery(sql, mapper, params);
		return list;
	}
	public bankUsers findById(int userid){
		String sql="select * from bankUsers where userid=? order by userid";
		Object params[]={userid};
		DBManager db=new DBManager();
		bankUsersMapper mapper=new bankUsersMapper();
		List<bankUsers> list=db.executeQuery(sql, mapper, params);
		if(list.size()!=0){
			return list.get(0);
		}else{
			return null;
		}
	}
	
//	public int getCount(){
//		String sql=" select count(*) from dept ";
//		Object params[]=null;
//		DBManager db=new DBManager();
//		int count=db.executeQueryCount(sql, params);
//		return count;			
//	}
//	public List<Dept>findByPage(int pagesize,int pagenow){
//		int start=(pagenow-1)*pagesize;
//		String sql=" select *from ";
//		sql+=" (select rownum rn,d.* from dept d ";
//		sql+=" order by d.deptno) ";
//		sql+=" where rn>? and rownum<=? ";
//		Object params[]={start,pagesize};
//		DBManager db=new DBManager();
//		DeptMapper mapper=new DeptMapper();
//		List<Dept> list=db.executeQuery(sql, mapper, params);
//		return list;
//	}
}
